package com.snail.common.toolUtil.fileutil;

import java.io.InputStream;
import java.util.Properties;

public class PropertiesUtil {

    public static Properties getProperties(String filepath) {
        Properties prop = new Properties();
        try {
            if (filepath == null) {//默认读取src.config下config.properties
                filepath = "application.yml";
            }
            InputStream in = PropertiesUtil.class.getClassLoader().getResourceAsStream(filepath);
            prop.load(in);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return prop;
    }


    /**
     * 获取config.properties文件某个属性值
     *
     * @param key 属性值key
     * @return 属性值value
     * @throws Exception
     */
    public static String readValue(String filePath, String key) {
        Properties props = getProperties(filePath);
        return props.getProperty(key);

    }

    /**
     * 获取具体某个属性值
     *
     * @param filePath 配置文件路径,null则默认为application.properties
     * @param key      属性值key
     * @return 属性值value
     * @throws Exception
     */
    public static String readValue(String key) {
        Properties props = getProperties(null);
        return props.getProperty(key);

    }

    public static void main(String[] args) {
        System.out.println();
    }
}
